﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhSystemBLL.orderData;
using dhDataAcess.baseBLL;
using baseSet.importExport;
using dhsystem.produceForm.picking;
using dhSystemBLL.produceBLL;
using baseSet.power;
using dhDataAcess.dataAcess;

namespace dhsystem.produceForm.pdrk
{
    public partial class Frmranse : Form
    {
        public Frmranse()
        {
            InitializeComponent();
        }
        orderDetailBLL orderDetail = new orderDetailBLL();
        pdpqbBLL pdpqb = new pdpqbBLL();
        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            //未排染单
            if (e.TabPage == tabPage1)
            {
                bgSourceweipai.DataSource = basicSql.getorderDetailII();
                dGridweipai.DataSource = bgSourceweipai;
                DcolumnSet.colSet(moduleInfo.orderDetail, dGridweipai);
            }
            //已排漂染单
            if (e.TabPage == tabPage2)
            {
                bgSourceyipai.DataSource = basicSql.getpdpqb();
                dGridyipai.DataSource  = bgSourceyipai;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi , dGridyipai);
            }
            //欠数染单
            if (e.TabPage == tabPage3)
            {
                bgSourceqianshu.DataSource = basicSql.getpdpqbqianshu();
                dGridqianshu.DataSource  = bgSourceqianshu;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridqianshu);
            }
            //染色完成染单
            if (e.TabPage == tabPage4)
            {
                bgSourceyiranse.DataSource = basicSql.getpdpqbranseend();
              dGridyiranse .DataSource = bgSourceyiranse;
              DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridyiranse);
            }
        }

        private void Frmranse_Load(object sender, EventArgs e)
        {
            bgSourceweipai.DataSource = basicSql.getorderDetailII();
            dGridweipai.DataSource = bgSourceweipai;
            DcolumnSet.colSet(moduleInfo.orderDetail, dGridweipai);

            sysDataSet.modulAaccessDataTable modulAaccess = powerSet.modulPower(moduleInfo.Pdpqb);
            foreach (sysDataSet.modulAaccessRow modulAaccessRow in modulAaccess)
            {
                buttonQuery.Enabled = modulAaccessRow.showAc;
                toolStripMenuItem1.Enabled = modulAaccessRow.addAc;
                欠数单ToolStripMenuItem.Enabled = modulAaccessRow.addAc;
                染色完成取消ToolStripMenuItem.Enabled = modulAaccessRow.editAc;
                欠数单ToolStripMenuItem.Enabled = modulAaccessRow.editAc;
                toolStripMenuItem3.Enabled = modulAaccessRow.editAc;
                修改排期ToolStripMenuItem1.Enabled = modulAaccessRow.editAc;
                取消排期ToolStripMenuItem.Enabled = modulAaccessRow.editAc;
               // toolDel.Enabled = modulAaccessRow.delAc;
                //toolPrint.Enabled = modulAaccessRow.printAc;
                toolStripButton17.Enabled = modulAaccessRow.exportAc;
                //buttImport.Enabled = modulAaccessRow.importAc;

            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string orderNo = dGridweipai.CurrentRow.Cells["orderNo"].Value.ToString();
            string orderDetailNo = dGridweipai.CurrentRow.Cells["orderDetailNo"].Value.ToString();
            orderMasterBLL orderMaster = new orderMasterBLL();
            bgSourceMaster.DataSource = orderMaster.getorderMasterAllByorderNo(orderNo);

            FrmpdpqbAdd pdpqbAdd = new FrmpdpqbAdd("新增", bgSourceMaster, orderDetailNo,"");
            DialogResult result = pdpqbAdd.ShowDialog();
            if (result == DialogResult.Yes)
            {
                bgSourceweipai.DataSource = basicSql.getorderDetailII();
                dGridweipai.DataSource = bgSourceweipai;
                DcolumnSet.colSet(moduleInfo.orderDetail, dGridweipai);
            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            string orderDetailNo = dGridyipai.CurrentRow.Cells["orderDetailNo"].Value.ToString();
            string billoNo = dGridyipai.CurrentRow.Cells["billoNo"].Value.ToString();
            Frmstartcoloration startcoloration = new Frmstartcoloration(billoNo,orderDetailNo);
            DialogResult result= startcoloration.ShowDialog();
            if(result ==DialogResult .Yes)
            {
                bgSourceyipai.DataSource = basicSql.getpdpqb();
                dGridyipai.DataSource  = bgSourceyipai;
                DcolumnSet.colSet(moduleInfo.Pdpqb, dGridyipai);
            }
        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 取消排单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            string billoNo = dGridyipai.Rows[dGridyipai.CurrentRow.Index].Cells[1].Value.ToString();
            try
            {
                DialogResult result = MessageBox.Show("是否取消排期：" + billoNo + "！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    string orderDetailNo = dGridyipai.CurrentRow.Cells["orderDetailNo"].Value.ToString();
                    
                    bgSourceyipai.DataSource = pdpqb.pdpqbDel(billoNo);
                    dGridyipai.DataSource = bgSourceyipai;
                    basicSql.getdetailStatusUpdate(orderDetailNo, "取消排期");
                    basicSql.getpdpqbStatusUpdate(orderDetailNo, "取消排期");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
           
            bgSourceyipai.DataSource = basicSql.getpdpqb();
            dGridyipai.DataSource = bgSourceyipai;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridyipai);
        

        }

        private void 修改排期ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string billoNo = dGridyipai.CurrentRow.Cells["billoNo"].Value.ToString();
            //string orderDetailNo = dGridyipai.CurrentRow.Cells["orderDetailNo"].Value.ToString();
            bgSourcepaiqi.DataSource = pdpqb.getV_piaoranpaiqiAllBybilloNo(billoNo);

            FrmpdpqbAdd pdpqbAdd = new FrmpdpqbAdd("编辑", bgSourcepaiqi, "", billoNo);
            DialogResult result = pdpqbAdd.ShowDialog();
            if (result == DialogResult.Yes)
            {
                bgSourceyipai.DataSource = basicSql.getpdpqb();
                dGridyipai.DataSource = bgSourceyipai;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridyipai);
            }
        }

        private void buttonQuery_Click(object sender, EventArgs e)
        {
            bgSourceweipaquery.DataSource = basicSql.getorderDetailIIII("%" + textbillNoQuery.Text + "%");
            dGridweipai.DataSource = bgSourceweipaquery;
            DcolumnSet.colSet(moduleInfo.orderDetail, dGridweipai);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            bgSourceyipai.DataSource = basicSql.getpdpqbII ("%" + textorderproduce.Text + "%");
            dGridyipai.DataSource = bgSourceyipai;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi , dGridyipai);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bgSourceyiranse.DataSource = basicSql.getpdpqbIII("%" + textBox3.Text + "%");
            dGridyiranse.DataSource = bgSourceyiranse;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridyiranse);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bgSourceqianshu.DataSource = basicSql.getorderDetailIII("%" + textBox2.Text + "%");
            dGridqianshu.DataSource = bgSourceqianshu;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridqianshu);
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.V_piaoranpaiqi , dGridyipai, "排单信息");
            frm.ShowDialog();
        }

        private void 染色完成取消ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否取消", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    basicSql.getdetailStatusUpdate(dGridyiranse.CurrentRow.Cells["orderDetailNo"].Value.ToString(), "开始染色");
                    basicSql.getpdpqbbillStatusUpdate(dGridyiranse.CurrentRow.Cells["billoNo"].Value.ToString(), "开始染色");
                    MessageBox.Show("取消成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
           bgSourceyiranse.DataSource = pdpqb.getpdpqbBybillStatus("染色完成");
              dGridyiranse .DataSource = bgSourceyiranse;
              DcolumnSet.colSet(moduleInfo.Pdpqb , dGridyiranse);
        }

        private void 欠数单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //string billoNo = dGridyiranse.CurrentRow.Cells["billoNo"].Value.ToString();
            //bgSourcepaiqi.DataSource = pdpqb.getV_piaoranpaiqiAllBybilloNo(billoNo);

            //FrmpdpqbAdd pdpqbAdd = new FrmpdpqbAdd("编辑", bgSourcepaiqi, "", billoNo);
            //DialogResult result = pdpqbAdd.ShowDialog();
            //if (result == DialogResult.Yes)
            //{
            //    bgSourceqianshu.DataSource = orderDetail.getorderDetailAllBydetailStatus("欠数");
            //    dGridqianshu.DataSource = bgSourceqianshu;
            //    DcolumnSet.colSet(moduleInfo.orderDetail, dGridqianshu);
            //}

            string orderNo = dGridyiranse.CurrentRow.Cells["orderNo"].Value.ToString();
            string orderDetailNo = dGridyiranse.CurrentRow.Cells["orderDetailNo"].Value.ToString();
            orderMasterBLL orderMaster = new orderMasterBLL();
            bgSourceMaster.DataSource = orderMaster.getorderMasterAllByorderNo(orderNo);

            FrmpdpqbAdd pdpqbAdd = new FrmpdpqbAdd("欠数", bgSourceMaster, orderDetailNo, "");
            DialogResult result = pdpqbAdd.ShowDialog();
            if (result == DialogResult.Yes)
            {
                bgSourceqianshu.DataSource = basicSql.getpdpqbqianshu();
                dGridqianshu.DataSource = bgSourceqianshu;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridqianshu);
            }
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            string orderDetailNo = dGridqianshu.CurrentRow.Cells["orderDetailNo"].Value.ToString();
            string billoNo = dGridqianshu.CurrentRow.Cells["billoNo"].Value.ToString();
            Frmstartcoloration startcoloration = new Frmstartcoloration(billoNo, orderDetailNo);
            DialogResult result = startcoloration.ShowDialog();
            if (result == DialogResult.Yes)
            {
                bgSourceqianshu.DataSource = basicSql.getpdpqbqianshu();
                dGridqianshu.DataSource = bgSourceqianshu;
                DcolumnSet.colSet(moduleInfo.Pdpqb, dGridqianshu);
            }
        }

        private void 取消排期ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string billoNo = dGridqianshu.CurrentRow.Cells["billoNo"].Value.ToString();
            try
            {
                DialogResult result = MessageBox.Show("是否取消排期：" + billoNo + "！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    string orderDetailNo = dGridqianshu.CurrentRow.Cells["orderDetailNo"].Value.ToString();

                    bgSourceqianshu.DataSource = pdpqb.pdpqbDel(billoNo);
                    dGridyipai.DataSource = bgSourceqianshu;
                    basicSql.getdetailStatusUpdate(orderDetailNo, "取消排期");
                    basicSql.getpdpqbDel(billoNo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

            bgSourceqianshu.DataSource = basicSql.getpdpqbqianshu();
            dGridqianshu.DataSource = bgSourceqianshu;
            DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridqianshu);
        }

        private void 修改排期ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string billoNo = dGridqianshu.CurrentRow.Cells["billoNo"].Value.ToString();
            //string orderDetailNo = dGridyipai.CurrentRow.Cells["orderDetailNo"].Value.ToString();
            bgSourceqianshu.DataSource = pdpqb.getV_piaoranpaiqiAllBybilloNo(billoNo);

            FrmpdpqbAdd pdpqbAdd = new FrmpdpqbAdd("欠数编辑", bgSourceqianshu, "", billoNo);
            DialogResult result = pdpqbAdd.ShowDialog();
            if (result == DialogResult.Yes)
            {
                bgSourceqianshu.DataSource = basicSql.getpdpqb();
                dGridqianshu.DataSource = bgSourceqianshu;
                DcolumnSet.colSet(moduleInfo.V_piaoranpaiqi, dGridqianshu);
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.V_piaoranpaiqi, dGridyipai, "排单信息");
            frm.ShowDialog();
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.V_piaoranpaiqi, dGridqianshu, "欠数单信息");
            frm.ShowDialog();
        }

        private void toolStripButton12_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.V_piaoranpaiqi, dGridyiranse, "染色完成信息");
            frm.ShowDialog();
        }

        private void toolStripButton17_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.orderDetail, dGridweipai, "未排染单信息");
            frm.ShowDialog();
        }

        private void toolStripButton20_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void toolStripButton10_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void toolStripButton15_Click(object sender, EventArgs e)
        {
            this.Close();
        }

   
    }
}
